﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using QLBH.DTO;
using System.Text.RegularExpressions;
using QLBH.Base;

namespace Module.Category
{
    public partial class AddCustomer : Form
    {
        private KhachHangDTO newCustomer;

        public KhachHangDTO NewCustomer
        {
            get { return newCustomer; }            
        }
        public AddCustomer()
        {
            InitializeComponent();
            newCustomer = new KhachHangDTO();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (!ValidInput())
            {
                return;
            }
            //ValidInput();

            newCustomer.DienChi = textBoxAddress.Text;
            newCustomer.Email = textBoxEmail.Text;
            newCustomer.SDT = textBoxPhoneNumber.Text;
            newCustomer.TenKH = textBoxName.Text;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        private bool ValidInput()
        {            
            try
            {
                DataInputHelper.CheckEmailData(textBoxEmail.Text);
            }
            catch (System.Exception ex)
            {
            	MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxEmail.SelectAll();
                textBoxEmail.Focus();
                return false;
            }
            try
            {
                DataInputHelper.CheckPhoneNumber(textBoxPhoneNumber.Text);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxPhoneNumber.SelectAll();
                textBoxPhoneNumber.Focus();
                return false;
            }
            try
            {
                DataInputHelper.CheckTextData(textBoxName.Text, "Tên Khách Hàng");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxName.SelectAll();
                textBoxName.Focus();
                return false;
            }           
            
            return true;
        }

        private void AddCustomer_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Escape)
            {
                this.Close();
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();

        }       
    }
}
